const DataBaseconnections = require('../app/database')
class UserService {
  async create(user) {
    const { name, password } = user
    const statement = `INSERT INTO users(name,password) VALUES(?,?);`
    // 将user存入数据库
    const results = await DataBaseconnections.execute(statement, [name, password])
    if (!results[1]) {
      return '注册成功'
    } else {
      return results
    }
  }
  async getUserByname(name) {
    const statement = `SELECT * FROM users WHERE name = ?;`
    // 将user存入数据库
    const results = await DataBaseconnections.execute(statement, [name])
    return results[0]
  }
}

module.exports = new UserService()
